home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / biz / dopus / SoundOpus.lha / Opus5 / ARexx / SoundOpus.dopus5
Text File  |  1999-01-01  |  13KB  |  534 lines

  1. /* $VER: SoundOpus.dopus5 2.0 (1.01.99)
  2.    ©1999 by Piotr Bieniek (adam@chemul.uni.lodz.pl)
  3.  
  4.  DOPUS5.5+ AREXX Script for all kinds of soundplaying
  5.  with ProgressBar-GUI and timecounter.
  6.  
  7.  Requirements:
  8.   * DOPUS 5.5
  9.   * MPEGA 3.3   (for playing MPEG-Audio)
  10.   * GMPlay 1.3  (for playing MIDI)
  11.   * Play16 1.8  (for playing samples)
  12.  
  13.   * RexxMaster (ARexx) running
  14.   * rexxsupport.library somewhere in LIBS:
  15.   * Break and List commands in C:
  16.   * PIPE: device mounted
  17.   * MPEG-Audio filetype installed in Opus (use this one included in
  18.     the package, or set ID of your own MPEG-Audio filetype to "MPA")
  19.   * MIDI filetype installed in Opus (use this one included in the
  20.     package, or set ID of your own MIDI filetype to "MIDI")
  21.   * a set of sample format filetypes installed in Opus (use these
  22.     included in the package, or set IDs of your own filetypes to
  23.     "WAVE", "VOC", "AIFF", "MAUD", "8SVX", "AU" and "CDDA")
  24.  
  25.  Description:
  26.   Integrates Dopus and MPEGA/GMPlay/Play16 for the best functionality
  27.   with playing all kinds of audio.  Displays Name/Soundformat/Time
  28.   in a Dopus progress window.  Shows the runtime on a
  29.   progressbar and a timecounter.
  30.  
  31.  Installation:
  32.   As button or menuitem:
  33.   <AREXX> Dopus5:ARexx/SoundOpus.dopus5 {Qp}
  34.  
  35.   For Filetype-startup (doubleclick start):
  36.   <AREXX> Dopus5:ARexx/SoundOpus.dopus5 {Qp} {Ql} {o}
  37.  
  38.   Before you start using the script you must configure it (paths for
  39.   MPEGA, GMPlay and Play16 executables must be given).
  40.  
  41.  Usage:
  42.   Select all sound files you want to listen and start SoundOpus.
  43.   If you want to stop playing a file press the abort button.
  44.   When you stop a file in the first five seconds, script will
  45.   be completely aborted.
  46.   You can also select directories. This script will look for all kinds
  47.   of sound files there (and in further subdirectories) and will add them
  48.   to the list of sounds to be played.
  49.  
  50.  Configuration:
  51.   Names of MPEGA, GMPlay and Play16 executables must be given in the
  52.   following variables:
  53.     mpegaexe - name (with path) for MPEGA executable file.
  54.     gmplayexe - name (with path) for GMPlay executable file.
  55.     play16exe - name (with path) for Play16 executable file.
  56.   You can also configure these programs for your needs by changing
  57.   other variables:
  58.     mpegamode - CLI arguments, which are passed to MPEGA.
  59.     gmplaymode - CLI arguments, which are passed to GMPlay.
  60.     play16mode - CLI arguments, which are passed to Play16.
  61. */
  62.  
  63. OPTIONS RESULTS
  64.  
  65. /* change this to configure the script */
  66. mpegaexe="MPEGA"
  67. mpegamode=""
  68. gmplayexe="Work:Music/GMPlay/GMPlay"
  69. gmplaymode=""
  70. play16exe="Play16"
  71. play16mode="PRE OUT=Paula8"
  72.  
  73. PARSE ARG portname' 'handle' 'filename
  74. ADDRESS VALUE portname
  75.  
  76. if Exists('T:SoundOpusRunning') then
  77.  do
  78.   DOPUS REQUEST '"SoundOpus script is already running" OK'
  79.   exit
  80.  end
  81. else
  82.  do
  83.   Open('file', 'T:SoundOpusRunning', 'w')
  84.   Close('file')
  85.  end
  86.  
  87. if ~Show(Libraries,"rexxsupport.library") then AddLib("rexxsupport.library",0,-30,0)
  88.  
  89. if handle="" then
  90.  do
  91.  
  92.   LISTER QUERY SOURCE
  93.   if rc~=0 then
  94.    do
  95.     DOPUS REQUEST '"You must have a source lister" OK'
  96.     Delete('T:SoundOpusRunning')
  97.     exit
  98.    end
  99.   else
  100.     parse var result handle .
  101.  
  102.   LISTER SET handle BUSY ON
  103.  
  104.   LISTER QUERY handle PATH
  105.   pfad=result
  106.  
  107.   cnt=0
  108.   LISTER QUERY handle SELENTRIES STEM entries.
  109.   if entries.count>0 then
  110.    do
  111.     do j=0 to entries.count-1
  112.       LISTER QUERY handle ENTRY '"'entries.j'"' STEM entry
  113.       if entry.type<0 then
  114.        do
  115.         DOPUS GETFILETYPE '"'pfad||entries.j'"' ID
  116.         if result="MPA" | result="MIDI" | result="CDDA" | result="WAVE" | result="VOC" | result="AIFF" | result="MAUD" | result="8SVX" | result="AU" then
  117.          do
  118.           filetypes.cnt=result
  119.           files.cnt=entries.j
  120.           cnt=cnt+1
  121.           LISTER SELECT handle '"'entries.j'"' OFF
  122.          end
  123.         else if result="binary" then
  124.          do
  125.           in=entries.j||'0a'x" was not recognized as a sound file"
  126.           dopus request '"'in'"' "CDDA|Skip"
  127.           if rc=1 then
  128.            do
  129.             filetypes.cnt="CDDA"
  130.             files.cnt=entries.j
  131.             cnt=cnt+1
  132.             LISTER SELECT handle '"'entries.j'"' OFF
  133.            end
  134.          end
  135.        end
  136.       else if entry.type>0 then
  137.        do
  138.         ADDRESS COMMAND 'List >T:SoundOpusList ALL FILES PAT ~(#?.info) LFORMAT %p%s "'pfad||entries.j'"'
  139.         Open('list', 'T:SoundOpusList', 'r')
  140.         do forever
  141.           fname=ReadLn('list')
  142.           if eof('list') then leave
  143.           DOPUS GETFILETYPE '"'fname'"' ID
  144.           if result="MPA" | result="MIDI" | result="CDDA" | result="WAVE" | result="VOC" | result="AIFF" | result="MAUD" | result="8SVX" | result="AU" then
  145.            do
  146.             filetypes.cnt=result
  147.             files.cnt=Substr(fname, Length(pfad)+1)
  148.             cnt=cnt+1
  149.            end
  150.         end
  151.         Close('list')
  152.         Delete('T:SoundOpusList')
  153.         LISTER SELECT handle '"'entries.j'"' OFF
  154.        end
  155.     end
  156.    end
  157.   files.count=cnt
  158.  end
  159.  
  160. else
  161.  
  162.  do
  163.   LISTER QUERY handle PATH
  164.   pfad=result
  165.   files.0=compress(filename,'"')
  166.   files.count=1
  167.   DOPUS GETFILETYPE '"'pfad||files.0'"' ID
  168.   filetypes.0=result
  169.  end
  170.  
  171.  
  172. if files.count=0 then
  173.  do
  174.   LISTER REFRESH handle
  175.   LISTER SET handle BUSY OFF
  176.   DOPUS REQUEST '"No sound files selected" OK'
  177.   Delete('T:SoundOpusRunning')
  178.   exit
  179.  end
  180.  
  181. LISTER SET handle BUSY OFF
  182. LISTER REFRESH handle
  183.  
  184.  
  185. DOPUS PROGRESS NAME FILE INFO BAR ABORT
  186. prhandle=result
  187. DOPUS PROGRESS prhandle TITLE 'Playing...'
  188.  
  189. do j=0 to files.count-1
  190.  
  191.   DOPUS PROGRESS prhandle BAR files.count j+1
  192.   DOPUS PROGRESS prhandle NAME Substr(files.j, Lastpos('/', files.j)+1)
  193.   DOPUS PROGRESS prhandle FILE 1 0
  194.  
  195.   if filetypes.j="MPA" then
  196.    do
  197.     if ~(PlayMPEG(files.j)) then leave
  198.    end
  199.   else if filetypes.j="MIDI" then
  200.    do
  201.     if ~(PlayMIDI(files.j)) then leave
  202.    end
  203.   else if filetypes.j="CDDA" then
  204.    do
  205.     if ~(PlaySample(files.j, 1)) then leave
  206.    end
  207.   else
  208.    do
  209.     if ~(PlaySample(files.j, 0)) then leave
  210.    end
  211.  
  212. end
  213.  
  214. DOPUS PROGRESS prhandle OFF
  215. Delete('T:SoundOpusRunning')
  216.  
  217. exit
  218.  
  219.  
  220.  
  221. PlayMPEG: procedure expose pfad prhandle mpegaexe mpegamode
  222.  
  223.   DOPUS PROGRESS prhandle INFO "Loading MPEG file / 00:00 / 00:00"
  224.  
  225.   filename='"'pfad||Arg(1)'"'
  226.  
  227.   ADDRESS COMMAND 'Run >T:mpegacli "'mpegaexe'" 'mpegamode' -T 'filename' >PIPE:mpegaout'
  228.   Open('cli', 'T:mpegacli', 'r')
  229.   process=ReadLn('cli')
  230.   parse var process '[CLI 'process']'
  231.   Close('cli')
  232.   Delete('T:mpegacli')
  233.  
  234.   Open('mpegaout','PIPE:mpegaout', 'r')
  235.  
  236.   do until string=""
  237.     if eof('mpegaout') then leave
  238.     string=ReadLineMPEG('mpegaout')
  239.   end
  240.  
  241.   do until index(string, "File Type:")>0
  242.     if eof('mpegaout') then leave
  243.     string=ReadLineMPEG('mpegaout')
  244.   end
  245.  
  246.   if ~eof('mpegaout') then
  247.    do
  248.     parse var string dummy"MPEG"mtype" "dummy"kbps "freq
  249.     mpgmode="MPEG"mtype" "freq
  250.  
  251.     string=ReadLineMPEG('mpegaout')
  252.     parse var string dummy": "pm":"ps
  253.  
  254.     ptotal=pm*60+ps
  255.     secs=0
  256.     DOPUS PROGRESS prhandle FILE ptotal 0
  257.    end
  258.  
  259.   do forever
  260.  
  261.     if eof('mpegaout') then leave
  262.     time=ReadCh('mpegaout',29)
  263.  
  264.     if index(time,"err")>0 then
  265.      do
  266.       dopus request "MPEGA reports an error:"'0a'x||time
  267.       leave
  268.      end
  269.  
  270.     time=left(right(time,10),5)
  271.     if time="" then leave
  272.     else parse var time min':'secs
  273.     secs=min*60+secs
  274.  
  275.     DOPUS PROGRESS prhandle INFO mpgmode" / "pm":"ps" / "time
  276.     DOPUS PROGRESS prhandle FILE ptotal secs
  277.  
  278.     DOPUS PROGRESS prhandle ABORT
  279.     if result then
  280.      do
  281.       ADDRESS COMMAND 'C:Break 'process' >NIL:'
  282.       if secs<6 then do
  283.         Close('mpegaout')
  284.         return 0
  285.       end
  286.       leave
  287.      end
  288.   end
  289.  
  290.   Close('mpegaout')
  291.  
  292. return 1
  293.  
  294. ReadLineMPEG: procedure
  295.   chn = Arg(1)
  296.   line = ''
  297.   do until eof(chn)
  298.     chr = Readch(chn, 1)
  299.     if (Verify(chr, '0a'x, 'm')>0) | (Verify(chr, '0d'x, 'm')>0) then leave
  300.     if Verify(chr, '1b'x, 'm')>0 then
  301.      do
  302.       esc=Readch(chn, 3)
  303.       if esc="[22" then Readch(chn, 1)
  304.      end
  305.     else
  306.       line=line||chr
  307.   end
  308. return line
  309.  
  310.  
  311.  
  312. PlayMIDI: procedure expose pfad prhandle gmplayexe gmplaymode
  313.  
  314.   DOPUS PROGRESS prhandle INFO "Loading MIDI file / 00:00 / 00:00"
  315.  
  316.   filename='"'pfad||Arg(1)'"'
  317.  
  318.   ADDRESS COMMAND 'Run >T:gmplaycli "'gmplayexe'" 'gmplaymode' VERBOSE 'filename' >PIPE:gmplayout'
  319.   Open('cli', 'T:gmplaycli', 'r')
  320.   process=Readln('cli')
  321.   parse var process '[CLI 'process']'
  322.   Close('cli')
  323.   Delete('T:gmplaycli')
  324.  
  325.   Open('gmplayout','PIPE:gmplayout', 'r')
  326.   Readch('gmplayout',210)
  327.  
  328.   do forever
  329.     if eof('gmplayout') then leave
  330.     iin=ReadLineMIDI('gmplayout')
  331.     if pos("MIDI Mode       : ",iin)>0 then
  332.      do
  333.       parse var iin "MIDI Mode       : "format"  "dummy
  334.       Readch('gmplayout',434)
  335.      end
  336.     else if pos("Length    : ",iin)>0 then
  337.      do
  338.       parse var iin "Length    : "pm":"ps"  "dummy
  339.       ptotal=pm*60+ps
  340.       zpm=pm
  341.       if length(pm)<2 then zpm="0"pm
  342.       Readch('gmplayout',350)
  343.      end
  344.     else if pos("(",iin)>0 then
  345.      do
  346.       parse var iin dummy"'"sname"'"dummy
  347.       DOPUS PROGRESS prhandle INFO "Loading '"sname"'"
  348.       Readch('gmplayout',20)
  349.      end
  350.     else if pos("Time: ",iin)>0 then leave
  351.  
  352.     DOPUS PROGRESS prhandle ABORT
  353.     if result then
  354.      do
  355.       ADDRESS COMMAND 'Break 'process' >NIL:'
  356.       Close('gmplayout')
  357.       return 0
  358.      end
  359.   end
  360.  
  361.   linelen=length(iin)+1
  362.  
  363.   do forever
  364.     if eof('gmplayout') then leave
  365.     if pos("Finished.",iin)>0 then leave
  366.     else if pos("Time:",iin)>0 then
  367.      do
  368.       mt=right(left(iin,7),2)
  369.       st=right(left(iin,10),2)
  370.       zmt=mt
  371.       if left(mt,1)=" " then
  372.        do
  373.         mt=right(mt,1)
  374.         zmt="0"mt
  375.        end
  376.       secs=mt*60+st
  377.       DOPUS PROGRESS prhandle INFO format" / "zpm":"ps" / "zmt":"st
  378.       DOPUS PROGRESS prhandle FILE ptotal secs
  379.      end
  380.  
  381.     DOPUS PROGRESS prhandle ABORT
  382.     if result then
  383.      do
  384.       ADDRESS COMMAND 'Break 'process' >NIL:'
  385.       if secs<6 then
  386.        do
  387.         Close('gmplayout')
  388.         return 0
  389.        end
  390.       leave
  391.      end
  392.  
  393.     iin=Readch('gmplayout',linelen)
  394.   end
  395.  
  396.   Close('gmplayout')
  397.  
  398. return 1
  399.  
  400.  
  401. ReadLineMIDI: procedure
  402.   chn=Arg(1)
  403.   line=''
  404.   do until eof(chn)
  405.     chr = Readch(chn, 1)
  406.     if (Verify(chr, '0a'x, 'm')>0) | (Verify(chr, '0d'x, 'm')>0) then leave
  407.     if Verify(chr, '1b'x, 'm')>0 then esc=Readch(chn, 2)
  408.     else
  409.       line=line||chr
  410.   end
  411. return line
  412.  
  413.  
  414.  
  415. PlaySample: procedure expose pfad prhandle play16exe play16mode
  416.  
  417.   DOPUS PROGRESS prhandle INFO "Loading sample / 00:00 / 00:00"
  418.  
  419.   filename='"'pfad||Arg(1)'"'
  420.  
  421.   if Arg(2) then ADDRESS COMMAND 'Run >T:play16cli "'play16exe'" 'play16mode' freq 44100 RAW bits 16 tracks 2 intel V=1 'filename' >PIPE:play16out'
  422.   else ADDRESS COMMAND 'Run >T:play16cli "'play16exe'" 'play16mode' V=1 'filename' >PIPE:play16out'
  423.   Open('cli', 'T:play16cli', 'r')
  424.   process=ReadLn('cli')
  425.   parse var process '[CLI 'process']'
  426.   Close('cli')
  427.   Delete('T:play16cli')
  428.  
  429.   iin=""
  430.   format=" RAW"
  431.   Open('play16out','PIPE:play16out', 'r')
  432.  
  433.   do forever
  434.     iin=ReadLineSample('play16out')
  435.     if index(iin,"Filetype")>0 then parse var iin "Filetype is"format"."
  436.     if index(iin,"tracks")>0 then parse var iin dummy": "tracks
  437.     if index(iin,"Bits")>0 then parse var iin dummy": "bits
  438.     if index(iin,"Compression")>0 then parse var iin dummy": "comp
  439.     if index(iin,"time")>0 then parse var iin dummy": "time
  440.     if index(iin,"frequency")>0 then parse var iin dummy": "freq
  441.     if index(iin,"playin")>0 then leave
  442.     if index(iin,"Error")>0 then
  443.      do
  444.       iin="Play16 reports an error:"||'0a'x||iin
  445.       dopus request '"'iin'"' "Oops"
  446.       Close('play16out')
  447.       return 1
  448.      end
  449.   end
  450.  
  451.   Time('R')
  452.  
  453.   parse var time pm":"ps
  454.   if tracks=1 then tracks="mono"
  455.   else tracks="stereo"
  456.   format=format" "bits"b-"tracks" "freq"Hz"
  457.   if ps>59 then
  458.    do
  459.     pm=pm+1
  460.     ps=ps-60
  461.    end
  462.   ptotal=pm*60+ps
  463.   if length(pm)<2 then pm="0"pm
  464.   if length(ps)<2 then ps="0"ps
  465.  
  466.   DOPUS PROGRESS prhandle FILE ptotal 0
  467.  
  468.   secs=0
  469.   azeit=0
  470.   mt=0
  471.   kst=0
  472.  
  473.   do while secs<ptotal
  474.  
  475.     st=secs-kst
  476.     if st>59 then
  477.      do
  478.       mt=mt+1
  479.       kst=kst+60
  480.       st=secs-kst
  481.      end
  482.  
  483.     zmt=mt
  484.     if length(mt)<2 then zmt="0"mt
  485.     zst=st
  486.     if length(st)<2 then zst="0"st
  487.  
  488.     DOPUS PROGRESS prhandle INFO format" / "pm":"ps" / "zmt":"zst
  489.     DOPUS PROGRESS prhandle FILE ptotal secs
  490.  
  491.     DOPUS PROGRESS prhandle ABORT
  492.  
  493.     if result then
  494.      do
  495.       ADDRESS COMMAND 'Break 'process' >NIL:'
  496.       if secs<6 then
  497.        do
  498.         Close('play16out')
  499.         return 0
  500.        end
  501.       leave
  502.      end
  503.  
  504.     secs=Trunc(Time('E'))
  505.     if secs=azeit then
  506.      do
  507.       Delay(25)
  508.       secs=Trunc(Time('E'))
  509.       azeit=secs
  510.      end
  511.  
  512.   end
  513.  
  514.   if secs=ptotal then
  515.    do
  516.     DOPUS PROGRESS prhandle INFO format" / "pm":"ps" / "pm":"ps
  517.     DOPUS PROGRESS prhandle FILE ptotal secs
  518.    end
  519.  
  520.   Close('play16out')
  521.  
  522. return 1
  523.  
  524. ReadLineSample:
  525. PROCEDURE
  526.   chn = Arg(1)
  527.   line = ''
  528.   do until eof(chn)
  529.     chr = Readch(chn, 1)
  530.     if (Verify(chr, '0a'x, 'm')>0) then leave
  531.     line=line||chr
  532.   end
  533. RETURN line
  534.